package cn.com.klun.tjy.other.tests;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 *
 */
public class TwoSum {
    public static void main(String[] args) {
        int[] numbers= new int[10000];
        Random random = new Random();
        for (int i = 0; i < 10000; i++) {
            numbers[i] = (i+1)*2;
        }
        int[] ints = twoSum(numbers, 20000);
        System.out.println("返回的坐标值"+ints[0]+":"+ints[1]);
    }
    // 1,2,3,4,5,6,7,8,9
    public static int[] twoSum(int[] numbers ,int target){
        long l = System.currentTimeMillis();
        int[] a = new int[]{0,0};
        Map<Integer,Integer> myMap =  new HashMap<>();
        int index1 , index2;
        index1 = 0;
        index2 = 0;
        int max = numbers.length;
        for (int i = 0; i < max; i++) {
            int number1 = numbers[i];
            for (int j = i; j < max; j++) {
                int number2 = numbers[j];
                if(number1+number2 == target){
                    System.out.println((System.currentTimeMillis()-l));
                    return new int[]{i+1,j+1};
                }
            }
            if(number1 >= target){
                System.out.println((System.currentTimeMillis()-l));
                return new int[]{0,0};
            }
        }
        System.out.println((System.currentTimeMillis()-l));
        return a ;
    }
}
